package org.example;

import java.security.*;
import java.nio.charset.StandardCharsets;

public class TestPath {
    public static void main(String[] args) throws Exception {
        String BASE_DIR = "/test";
        String fname = "WO2023048639A8.pdf";

        // prefix
        String prefix = fname.substring(0, 2).toUpperCase();
        if (!prefix.matches("[A-Z]{2}")) {
            prefix = "UN";
        }

        // hash
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(fname.getBytes(StandardCharsets.UTF_8));
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(String.format("%02x", b));
        }
        String hash = sb.toString();
        System.out.println(hash);
        String b1 = hash.substring(0, 2);
        String b2 = hash.substring(2, 4);

        System.out.println(BASE_DIR + "/" + prefix + "/" + b1 + "/" + b2 + "/" + fname);
    }
}
